<template>
	<view class="main">
		<view class="content">
			<view class="">
				<view class="top" :style="{ paddingTop: systemInfo.titleTop + 'px' }">
					<view class="main-title" :style="{ height: systemInfo.sBarHeight + 'px', 'line-height': systemInfo.sBarHeight + 'px' }">个人信息</view>
				</view>
			</view>
			<view class="user">
				<view class="name-box">
					<view class="name">{{ userInfo.userName }}</view>
					<view class="z">正式员工</view>
				</view>
				<view class="b">
					<view class="b-name">{{ userInfo.projectName }}</view>
					<view class="b-l" @click="$goURl('/pages/index/dimission')">申请离职</view>
				</view>
				<view class="time">入职时间：{{ userInfo.hireDate }}</view>
			</view>

			<view class="user" style="margin: 16rpx 0">
				<view class="kf-box">
					<view class="icon">
						<image src="/static/kf.png" mode="aspectFill"></image>
						<button class="kf" open-type="contact">客服</button>
					</view>
					<view class="r">
						<image src="/static/ri.png" mode="aspectFill"></image>
					</view>
				</view>
			</view>

			<view class="list">
				<view class="x-title">
					<view class="t-left"></view>
					<view class="t-right">系统消息</view>
				</view>
				<view class="content">
					<scroll-view scroll-y="true" class="scroll-Y">
						<Empty v-if="!msgList.length" />
						<view class="item" v-for="(item, index) in msgList" v-else :key="index">
							<view class="gg">
								<image src="/static/gg.png" mode="aspectFill"></image>
							</view>
							<view class="con">
								<view class="con-top">
									<view class="c-t-left">{{ item.title }}</view>
									<view class="c-t-right">{{ item.addTime.split(' ')[0] }}</view>
								</view>
								<view class="detail .over-2">
									{{ item.brief }}
									<view class="look" @click="$goURl(`/pages/index/noticeDetail?data=${encodeURIComponent(JSON.stringify(item))}`)">
										<view class="box">
											<view class="l-name">查看详情</view>
											<image src="/static/r.png" mode="aspectFill"></image>
										</view>
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
		<view class="n" :style="{ height: systemInfo.titleTop + systemInfo.sBarHeight + 'px', paddingTop: systemInfo.titleTop + 'px', opacity: nOpacity }">个人信息</view>
	</view>
</template>

<script setup>
import { ref, nextTick, reactive, onMounted } from 'vue';
import { onPageScroll, onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
import { getUserInfo, getNotice } from '@/api/apiList';

const userInfo = ref({});
const getUser = async () => {
	const userRes = await getUserInfo();
	if (userRes.code == 200) {
		userInfo.value = userRes.data;
	}
};

// 获取通知
let query = reactive({
	pageNum: 1,
	pageSize: 10,
	reasonable: false
});
const msgList = ref([]);
const getMsg = async () => {
	const res = await getNotice(query);
	if (res.code == 200) {
		if (res.data.length) {
			msgList.value = [...msgList.value, ...res.data];
		}
	}
};

onReachBottom(() => {
	query.pageNum++;
	getMsg();
});

onPullDownRefresh(() => {
	uni.showLoading({
		title: '加载中'
	});
	query.pageNum = 1;
	msgList.value = [];
	getUser();
	getMsg();
	uni.hideLoading();
	uni.stopPullDownRefresh();
});

onLoad(() => {
	getUser();
	getMsg();
});

let topH = ref(0);
onMounted(() => {
	let view = uni.createSelectorQuery().select('.list');
	view.boundingClientRect((data) => {
		const { top } = data;
		topH.value = top;
	}).exec();
});

const showNav = ref(false);
const nOpacity = ref(0);
onPageScroll((res) => {
	const { scrollTop } = res;
	let value = scrollTop / 100;
	nOpacity.value = scrollTop >= systemInfo.sBarHeight - systemInfo.titleTop ? value : 0;
});

const capsule = uni.getStorageSync('capsule');
let systemInfo = uni.getStorageSync('systemInfo');
</script>

<style>
/* page {
	height: 100%;
	background: linear-gradient(180deg, #2b77ff 0%, #f9f9f9 45%);
} */
</style>

<style lang="scss" scoped>
.n {
	background: #4f7ff7;
	// height: 54rpx;
	width: 100%;
	display: flex;
	align-items: center;
	font-family: Source Han Sans, Source Han Sans;
	font-weight: 500;
	font-size: 36rpx;
	color: rgba(255, 255, 255, 0.851);
	line-height: 24rpx;
	box-sizing: border-box;
	position: fixed;
	top: 0;
	padding-left: 32rpx;
	z-index: 1;
	// left: 0;
	// right: 0;
}
.over-2 {
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}
.main {
	height: 100vh;
	background: linear-gradient(180deg, #2b77ff 0%, #fff 45%);
}
.content {
	padding: 0 32rpx;
}
.main-title {
	font-family: Source Han Sans, Source Han Sans;
	font-weight: 500;
	font-size: 36rpx;
	color: #fff;
}

.user:last-child {
	margin-top: 0;
	margin: 16rpx 0;
}
.user {
	background: #ffffff;
	border-radius: 20rpx;
	padding: 32rpx;
	margin-top: 60rpx;

	.kf-box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		.r {
			image {
				width: 32rpx;
				height: 32rpx;
			}
		}
		.icon {
			display: flex;
			align-items: center;
			image {
				width: 40rpx;
				height: 40rpx;
			}
			.kf {
				background-color: transparent;
				display: flex;
				justify-content: flex-start;
				width: 500rpx;
				font-family: Source Han Sans, Source Han Sans;
				font-weight: 400;
				font-size: 28rpx;
				color: #3d3d3d;
			}
		}
	}

	.time {
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #7b7b7b;
	}
	.b {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 20rpx 0;
		.b-name {
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 400;
			font-size: 28rpx;
			color: #3d3d3d;
		}
		.b-l {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 144rpx;
			height: 60rpx;
			border-radius: 32rpx;
			border: 2rpx solid #80adff;
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 400;
			font-size: 24rpx;
			color: #2b77ff;
		}
	}
	.name-box {
		display: flex;
		align-items: center;
		.name {
			margin-right: 18rpx;
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 500;
			font-size: 40rpx;
			color: #3d3d3d;
		}
		.z {
			display: flex;
			align-items: center;
			justify-content: center;
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 400;
			font-size: 20rpx;
			color: #ffffff;
			background: #2b77ff;
			border-radius: 16rpx;
			padding: 10rpx 20rpx;
		}
	}
}

.list {
	background: #ffffff;
	border-radius: 20rpx 20rpx 0rpx 0rpx;
	.content {
		padding: 0 24rpx;
		.scroll-Y {
			.item:first-child {
				border-top: 1rpx solid #f5f5f5;
			}
			.item {
				padding: 28rpx 0;
				display: flex;
				border-bottom: 1rpx solid #f5f5f5;
				.con {
					width: 100%;

					.detail {
						font-family: Source Han Sans, Source Han Sans;
						font-weight: 400;
						font-size: 24rpx;
						color: #6a6a6a;
						line-height: 36rpx;
						margin-top: 22rpx;
						position: relative;
						.look {
							position: absolute;
							right: 0;
							bottom: 0;
							display: flex;
							justify-content: flex-end;
							margin-top: 10rpx;
							background-color: #fff;
							padding-left: 20rpx;
							.box {
								display: flex;
								align-items: center;
								.l-name {
									font-family: Source Han Sans, Source Han Sans;
									font-weight: 400;
									font-size: 24rpx;
									color: #2b77ff;
								}
								image {
									width: 28rpx;
									height: 28rpx;
								}
							}
						}
					}
					.con-top {
						display: flex;
						justify-content: space-between;
						align-items: center;
						.c-t-left {
							font-family: Source Han Sans, Source Han Sans;
							font-weight: 400;
							font-size: 28rpx;
							color: #1a1a1a;
						}
						.c-t-right {
							font-family: Source Han Sans, Source Han Sans;
							font-weight: 400;
							font-size: 24rpx;
							color: #858585;
						}
					}
				}
				.gg {
					border-radius: 50%;
					margin-right: 10rpx;
					width: 44rpx;
					height: 44rpx;
					background: #0256ff;
					display: flex;
					justify-content: center;
					align-items: center;
					image {
						width: 18rpx;
						height: 18rpx;
					}
				}
			}
		}
	}
	.x-title {
		display: flex;
		align-items: center;
		padding: 32rpx 0;
		.t-left {
			width: 10rpx;
			height: 24rpx;
			background: #2b77ff;
			margin-right: 20rpx;
		}
		.t-right {
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 500;
			font-size: 32rpx;
			color: #3d3d3d;
		}
	}
}
</style>
